package com.services.impl;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectResult;
import com.services.forms.UploadFileResult;
import com.services.interfaces.IAliyunService;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.*;


/**
 * Created by Administrator on 2017/4/12.
 */
@Service
public class AliyunService implements IAliyunService {

//    @Value("${aliyun.oss.access.key}")
//    private String aliyun_access_key;
//
//    @Value("${aliyun.oss.secret.key}")
//    private String aliyun_secret_key;
//
//    @Value("${aliyun.bucket.name}")
//    private String aliyun_bucket_name;
//
//    @Value("${aliyun.folder.name}")
//    private String aliyun_folder_name;
//
//    @Value("${aliyun.oss.endpoint}")
//    private String aliyun_endpoint;

    @Override
    public UploadFileResult uploadFile( InputStream content,long length, String key) {
//        try {
//            OSSClient client = new OSSClient(aliyun_endpoint, aliyun_access_key, aliyun_secret_key);
//            ObjectMetadata meta = new ObjectMetadata();
//            meta.setContentLength(length);
//            PutObjectResult result = client.putObject(aliyun_bucket_name, aliyun_folder_name + "/" + key, content, meta);
//            String imgurl = "http://" + aliyun_bucket_name + ".oss.aliyuncs.com/" + aliyun_folder_name + "/" + key;
//            content.close();
//            return UploadFileResult.success(imgurl);
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//            return UploadFileResult.fail(e.toString());
//        } catch (IOException e) {
//            e.printStackTrace();
//            return UploadFileResult.fail(e.toString());
//        }
        return null;
    }
}
